import emitter from "../utils/eventbus";
import * as d3 from "d3";

export function initTubings($: any, d3CanvasRef: any, width: number, heightStart: number, heightEnd: number) {
    let id: string = $.attr("id");
    const d3Canvas = d3CanvasRef;//画布信息
    const widthCenter = d3Canvas.offsetWidth / 2 //中心线
    const drillPioe = { left: undefined, right: undefined }
    drillPioe.left = $.append("line")
        .attr("x1", widthCenter - width / 2)
        .attr("y1", heightStart)
        .attr("x2", widthCenter - width / 2)
        .attr("y2", heightEnd)
        .attr("stroke-width", 2)
        .attr("stroke", "red");
    drillPioe.right = $.append("line")
        .attr("x1", widthCenter + width / 2)
        .attr("y1", heightStart)
        .attr("x2", widthCenter + width / 2)
        .attr("y2", heightEnd)
        .attr("stroke-width", 2)
        .attr("stroke", "red");
    const drag = d3
        .drag()
        .on("drag", (event) => {
            const newY2 = event.y;
            drillPioe.left.attr("y2", newY2);
            drillPioe.right.attr("y2", newY2);
        });

    // 应用拖动行为到线段上
    drillPioe.left.call(drag);
    drillPioe.right.call(drag)
    emitter.on(id, (transform: any) => {
        drillPioe.left.attr("transform", transform);
        drillPioe.right.attr("transform", transform);
    });
}